<?php
/**
* Name:  My Controller
*
* Author: Ray Nowell
*
* Created:  10/26/2010
*
* Description:  Extends CI's controller 
*
*/
 
class MY_Controller extends Controller
{
	//REN TODO:  Use this vars in child classes to prevent the large amount of query class used to get this vars
	protected $is_admin = false;
	protected $current_facility_id = 0;
	protected $current_user = 'not set';
	protected $current_facility_name;
                    
	function MY_Controller ($must_be_admin = false)  
	{
		parent::Controller();
		
		//If user is notlogged on, redirect to login
		if (!$this->ion_auth->logged_in()) 
			redirect('auth/login'); //REN Change:  Remove 'refresh option to fix on PPG's network*
		
		//If the user must be an administrator and the user is not administrator, go back to welcome screen
		$is_admin	=	$this->ion_auth->is_admin(); 
		if ($must_be_admin && !$is_admin)
			redirect('welcome'); //REN Change:  Remove 'refresh option to fix on PPG's network*
		
		$user = $this->ion_auth->get_user();
		$this->is_admin					=	$is_admin;
		$this->current_facility_id		=	$user->current_facility_id;
		$this->current_user				=	$user->username;
		$this->current_facility_name	=	$this->master_view_functions->get_user_facility_name();
	}
	/*
	 * DEV NOTE: Having the following line of code was causing problems on PPG's network:
	 * redirect('auth/login');
	 * 
	 * I don't know what is causing the problem, but I do know which line of code it was.
	 * In the "function redirect" method of the URL helper, there is this line of code:
	 * case 'refresh'	: header("Refresh:0;url=".$uri);
	 * The PHP header command does not work with the string "Refresh on Brian's network."
	 * 
	 * I don't know why.  I posted the following question in stack overflow, but I'm not expecting any good answers:
	 * http://stackoverflow.com/questions/3908540/headerrefresh-makes-page-blank-but-only-on-one-network
	 * 
	 * If removing the refresh porition of the code causes issues on other servers, I may have to do something like this:
	 * 
	 * redirect('auth/login','refresh');  //Try this first
	 * redreict('auth/login'); //Then try this 
	 * 
	 */
} 
/* End of MY_Controller.php */
/* Location: ./system/application/libraries/MY_controller.php */

